<template>
  <div>
    <div class="address">
      <div class="addressspace">
        <el-space>
          <el-input v-model.trim="userId" placeholder="请输入用户ID" />
          <el-button type="primary" class="iconfont icon-sousuo" @click="seek()"
            >查找</el-button
          >
        </el-space>
      </div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="地址ID" align="center" />
        <el-table-column prop="userId" label="用户ID" align="center" />
        <el-table-column prop="consignee" label="签收人" align="center" />
        <el-table-column prop="phone" label="签收人" align="center" />
        <el-table-column prop="city" label="省份" align="center" />
        <el-table-column prop="province" label="城市" align="center" />
        <el-table-column prop="county" label="区县" align="center" />
        <el-table-column prop="address" label="详情地址" align="center" />
      </el-table>
      <!-- 分页组件 -->
      <PagLnatio
        class="dins"
        v-bind="paging"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </PagLnatio>
    </div>
  </div>
</template>

<script>
import PagLnatio from "@/components/PagLnatio.vue";
import http from "@/http";
export default {
  components: {
    PagLnatio,
  },
  data() {
    return {
      tableData: [],
      userId: "",
      paging: {
        page: 1, //默认第一页
        limit: 10, //显示几页
        total: null,
      },
    };
  },
  created() {
    this.address();
  },
  methods: {
    address() {
      let data = {
        _gp: "admin.address",
        _mt: "list",
        userId: this.userId,
        page: this.paging.page,
        limit: this.paging.limit,
      };
      http.post(data).then((res) => {
        console.log(res);
        if (200 == res.errno) {
          this.paging.total = res.data.total;
          this.tableData = res.data.items;
        }
      });
    },
    seek() {
      if (this.userId == "") {
        return ElMessage.error("查找用户ID不能为空！");
      }
      this.address();
    },
    handleSizeChange(val) {
      this.paging.limit = val;
      this.address();
    },
    handleCurrentChange(val) {
      this.paging.page = val;
      this.address();
    },
  },
};
</script>

<style lang="less" scope>
.address {
  width: 98%;
  margin: auto;
  .addressspace {
    height: 40px;
  }
}
</style>
